package cn.elricyu.tt.util;

import java.util.UUID;

import org.apache.commons.lang.StringUtils;


/**
 * 
 * @author chunping.zhongcp
 *
 */
public class UUIDUtil {

	private static final String MIDDLE_LINE = "-";


	private static char X36S[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
			.toCharArray();


	private static short LEN = 20;


	public static String random36() {
		return UUID.randomUUID().toString().toUpperCase();
	}


	public static String random32() {
		return StringUtils.remove(UUID.randomUUID().toString(), MIDDLE_LINE)
				.toUpperCase();
	}


	public static String random20() {
		char chs[] = new char[LEN];

	
		long v = (System.currentTimeMillis() - 936748800000L) >> 1; // 1999-9-9

		for (int i = 7; i > 0; i--) {
			chs[i] = X36S[(int) (v % 36)];
			v = v / 36;
		}
		chs[0] = X36S[(int) (v % 26) + 10];


		UUID u = UUID.randomUUID();
		v = u.getLeastSignificantBits() ^ u.getMostSignificantBits();
		if (v < 0) {
			v = -v;
		}

		for (int i = 8; i < LEN; i++) {
			chs[i] = X36S[(int) (v % 36)];
			v = v / 36;
		}

		return new String(chs).toUpperCase();
	}

}
